const Sequelize = require('sequelize')
module.exports = (sequelize, DataTypes) => {
  return CdAnnotation.init(sequelize, DataTypes)
}

class CdAnnotation extends Sequelize.Model {
  static init(sequelize, DataTypes) {
    super.init(
      {
        id: {
          type: DataTypes.CHAR(32),
          allowNull: false,
          primaryKey: true,
          comment: '主键',
        },
        detectorId: {
          type: DataTypes.CHAR(32),
          allowNull: false,
          comment: '检测任务',
          field: 'detector_id',
        },
        image: {
          type: DataTypes.STRING(20),
          allowNull: false,
          comment: '图片名',
        },
        total: {
          type: DataTypes.INTEGER,
          allowNull: false,
          defaultValue: 0,
          comment: '检测到的细胞总数',
        },
        cls1: {
          type: DataTypes.INTEGER,
          allowNull: false,
          defaultValue: 0,
          comment: '类型1的细胞总数',
        },
        cls2: {
          type: DataTypes.INTEGER,
          allowNull: false,
          defaultValue: 0,
          comment: '类型2的细胞总数',
        },
        cls3: {
          type: DataTypes.INTEGER,
          allowNull: false,
          defaultValue: 0,
          comment: '类型3的细胞总数',
        },
        cls4: {
          type: DataTypes.INTEGER,
          allowNull: false,
          defaultValue: 0,
          comment: '类型4的细胞总数',
        },
        cls5: {
          type: DataTypes.INTEGER,
          allowNull: false,
          defaultValue: 0,
          comment: '类型5的细胞总数',
        },
        cls6: {
          type: DataTypes.INTEGER,
          allowNull: false,
          defaultValue: 0,
          comment: '类型6的细胞总数',
        },
        result: {
          type: DataTypes.JSON,
          allowNull: true,
        },
        createTime: {
          type: DataTypes.DATE,
          allowNull: false,
          defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
          comment: '检测时间',
          field: 'create_time',
        },
      },
      {
        sequelize,
        tableName: 'cd_annotation',
        timestamps: true,
        underscored: true,
        createdAt: 'createTime',
        updatedAt: false,
        indexes: [
          {
            name: 'PRIMARY',
            unique: true,
            using: 'BTREE',
            fields: [{ name: 'id' }],
          },
          {
            name: 'detector_id',
            using: 'BTREE',
            fields: [{ name: 'detector_id' }],
          },
        ],
      },
    )
    return CdAnnotation
  }
}
